package com.timebank.timecoin.factory;

import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.timecoin.pojo.entity.User;
import com.timebank.timecoin.service.RemoteContractService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 智能合约服务 降级处理
 * @author shiliuyinzhen
 */
@Component
public class RemoteContractFallBackFactory implements FallbackFactory<RemoteContractService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteContractFallBackFactory.class);

    @Override
    public RemoteContractService create(Throwable throwable) {

        return new RemoteContractService() {

            @Override
            public AjaxResult updateContractUser(User user, String source) {
                return AjaxResult.error("更新智能合约用户信息调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult createContractUser(User user, String source) {
                return AjaxResult.error("添加智能合约用户调用失败：{}" + throwable.getMessage());
            }
        };
    }
}
